﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using SocialIn.Core;
using SocialIn.Biz;

namespace SocialIn.Web.UserControls
{
    public partial class UCHeader : System.Web.UI.UserControl
    {
        public string UserName { get; set; }
        public int UserKey { get; set; }

        public bool IsUsingForHomePage { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CILogoPanel.Visible = !IsUsingForHomePage; 
         
                if (HttpContext.Current.Session[ConfigName.SessionMember] != null)
                {
                    AfterLoginPanel.Visible = true;
                    Member member = (Member)HttpContext.Current.Session[ConfigName.SessionMember];

                    if (member != null)
                    {
                        UserName = member.UserName;
                    }
                }
                else
                {
                    AfterLoginPanel.Visible = false;
                }
            }
        }

        /// <summary>
        /// 마이 페이지 이동
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnMyPage_Click(object sender, EventArgs e)
        {
            Member member = (Member)HttpContext.Current.Session[ConfigName.SessionMember];
            if (member.UserType.Equals("R002"))
            {
                // 받으미
                Response.Redirect("/GiveAndTake/TakeInformation.aspx");
            }
            else if (member.UserType.Equals("R003"))
            {
                // 드리미
                Response.Redirect("/MyPage/Iam.aspx");
            }
            else
            {
                Response.Redirect("/Main.aspx");
            }
        }

        /// <summary>
        /// 로그 아웃 처리
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnLogOut_Click(object sender, EventArgs e)
        {
            Connect connect = new Connect();
            connect.LogOut("/Main.aspx");
        }
    }
}